" Setting some decent VIM settings for programming

set ai                          " set auto-indenting on for programming
set showmatch                   " automatically show matching brackets. works like it does in bbedit.
set vb                          " turn on the "visual bell" - which is much quieter than the "audio blink"
set ruler                       " show the cursor position all the time
set laststatus=2                " make the last line where the status is two lines deep so you can see status always
set backspace=indent,eol,start  " make that backspace key work the way it should
set nocompatible                " vi compatible is LAME
set background=dark             " Use colours that work well on a dark background (Console is usually black)
set showmode                    " show the current mode
set clipboard=unnamed           " set clipboard to unnamed to access the system clipboard under windows
syntax on                       " turn syntax highlighting on by default

" Show EOL type and last modified timestamp, right after the filename
set statusline=%<%F%h%m%r\ [%{&ff}]\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))})%=%l,%c%V\ %P

"------------------------------------------------------------------------------
" Only do this part when compiled with support for autocommands.
if has("autocmd")
    "Set UTF-8 as the default encoding for commit messages
    autocmd BufReadPre COMMIT_EDITMSG,git-rebase-todo setlocal fileencodings=utf-8

    "Remember the positions in files with some git-specific exceptions"
    autocmd BufReadPost *
      \ if line("'\"") > 0 && line("'\"") <= line("$")
      \           && expand("%") !~ "COMMIT_EDITMSG"
      \           && expand("%") !~ "ADD_EDIT.patch"
      \           && expand("%") !~ "addp-hunk-edit.diff"
      \           && expand("%") !~ "git-rebase-todo" |
      \   exe "normal g`\"" |
      \ endif

      autocmd BufNewFile,BufRead *.patch set filetype=diff
      autocmd BufNewFile,BufRead *.diff set filetype=diff

      autocmd Syntax diff
      \ highlight WhiteSpaceEOL ctermbg=red |
      \ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/

      autocmd Syntax gitcommit setlocal textwidth=74
endif " has("autocmd")

" 解决在MinGW下VIM显示中文乱码的问题
set nu
set fencs=utf-8,gbk,utf-16,utf-32,ucs-bom

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim editor settings.
" :help
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Start Vim with a maximized window.
" :help gui-win32-maximized
" au GUIEnter * simalt ~x

" Describe what components and options of the GUI should be used.
" :help 'guioptions'
set guioptions=e

" Specify the label to display for each tab page.
" %N - Tab page number.
" %t - Name (tail) of active file in the buffer.
" %h - Help buffer flag, text is "[help]".
" %r - Readonly flag, text is "[RO]".
" %m - Modified flag, text is "[+]"; "[-]" if 'modifiable' is off.
" :help 'guitablabel'
" :help 'statusline'
set guitablabel=%N.\ %t%h%r%m

" Set the color scheme.
" :help :colorscheme
colorscheme darkblue

" Show the line and column number of the cursor position, separated by a comma.
" help 'ruler'
set ruler

" Print the line number in front of each line.
" :help 'number'
set number

" Show (partial) command in the last line of the screen.
" :help 'showcmd'
set showcmd

" If in Insert, Replace or Visual mode put a message on the last line.
" :help 'showmode'
set showmode

" Set no wrap display.
" :help 'wrap'
set nowrap

" Set backup options.
" :help 'backup'
" :help 'writebackup'
set nobackup            " Don't keep the backup file.
set writebackup         " Backup the current file before writting.

" Enable file type detection.
" :help :filetype
filetype on

" Copy indent from current line when starting a new line (typing <CR>
" in Insert mode or when using the "o" or "O" command).
" :help 'autoindent'
set autoindent

" A history of ":" commands, and a history of previous search patterns
" are remembered.
" :help 'history'
set history=50

" Set the maximum width of text.
" :help 'textwidth'
set textwidth=100

" While typing a search command, show where the pattern, as it was typed
" so far, matches.
" :help 'incsearch'
set incsearch

" Set the size of windows.
" Notice: 'winminheight' and 'winminwidth' should be set earlier than
"         'winheight' and 'winwidth'.
" :help 'winheight'
" :help 'winminheight'
" :help 'winwidth'
" :help 'winminwidth'
" :help 'equalalways'
set winminheight=1      " Minimal height of other windows.
set winminwidth=1       " Minimal width of other windows.
set winheight=1         " Minimal height of the current window.
set winwidth=20         " Minimal width of the current window.
set equalalways         " Make all the windows the same size
                        " after splitting or closing a window.

" Set the width of <TAB>.
" :help 'tabstop'
" :help 'shiftwidth'
" :help 'softtabstop'
" :hlep 'expandtab'
set tabstop=4           " Number of spaces the existed <Tab> counts for.
set shiftwidth=4        " Number of spaces to use for (auto)indent.
set softtabstop=4       " Number of spaces to use for <Tab> and <BS>.
set expandtab           " Use spaces to insert a <Tab>.

" Set help language.
" :help 'helplang'
set helplang=en

" Set the path of work directory.
" :help 'path'
set path=.

" Map <F7> to change colorscheme.
" map <F7> :colorscheme <Tab><CR>

" Map <F9> to search.
" vnoremap <F9> y:exe "grep /" . escape(@", '\\/') . "/ *.c *.h"<CR>

" Set character encoding.
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8

set fileformat=unix


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cindent settings.
" :help 'cindent'
" :help 'cinoptions'
" :help cinoptions-values
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Place case labels N characters from the indent of the switch().
" help cino-:
set cinoptions=:0


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Netrw plugin settings.
" :help netrw
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Set the tree style as the default listing style.
" :help netrw-i
let g:netrw_liststyle=0

" Specify initial size of new windows made with "o" (see netrw-o),
" "v" (see netrw-v), :Hexplore or :Vexplore.
" :help g:netrw_winsize
let g:netrw_winsize=-30

" Control right/left splitting when using "v"(see netrw-v).
" :help g:netrw_altv
let g:netrw_altv=0


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ctags plugin settings.
" :help ctags
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Set the path of tags file.
" :help 'tags'
" set tags=./tags

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Taglist plugin settings.
" Run the ":helptags {dir}" command first to process the taglist help file,
" where {dir} is the directory of taglist's help file <taglist.txt>.
" :help taglist.txt
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Specify the location (path) of the exuberant ctags utility.
" :help 'Tlist_Ctags_Cmd'
let Tlist_Ctags_Cmd='/usr/bin/ctags'

" Automatically open the tags tree for the current buffer and close all the
" other buffers.
" :help 'Tlist_File_Fold_Auto_Close'
let Tlist_File_Fold_Auto_Close=1

" When a new file is edited, the tags defined in the file are automatically
" processed and added to the taglist.
" :help 'Tlist_Auto_Update'
let Tlist_Auto_Update=1

" Display the tags defined only in the current buffer.
" :help 'Tlist_Show_One_File'
let Tlist_Show_One_File=1

" Specify the default width of the vertically split taglist window.
" :help 'Tlist_WinWidth'
let Tlist_WinWidth=33

" Create a normal mode mapping for the <F8> key to toggle the taglist window.
" :help taglist-using
nnoremap <silent> <F8> :TlistToggle<CR>
